using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CsharpCallArkTs : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
#if UNITY_OPENHARMONY && !UNITY_EDITOR
        OpenHarmonyJSClass  openHarmonyJSClass = new OpenHarmonyJSClass("OpenHarmonyJSClassTest");
        openHarmonyJSClass.CallStatic("Func1");
        Debug.Log("[test] static Func1 was called");
        
        string param1 = "hello world";
        var res = openHarmonyJSClass.CallStatic<string>("Func2", param1);
        Debug.Log("[test] static Func2 was called,  res=" + res );

        OpenHarmonyJSCallback callback = new OpenHarmonyJSCallback(args => {
            int p1 = args[0].As<int>();
            int p2 = args[1].As<int>();
            var res = p1 * p2;
            Debug.Log("[test] static Func3 callback result=" + res);
            return null;
        });   
        openHarmonyJSClass.CallStatic("Func3", callback);
        
        OpenHarmonyJSObject openHarmonyJSObject = new OpenHarmonyJSObject("OpenHarmonyJSObjectTest");
        openHarmonyJSObject.Call("Func4");
        Debug.Log("[test] Func4 was called");

        string param2 = "zhansan";
        var res2 = openHarmonyJSObject.Call<int>("Func5", param2);
        Debug.Log("[test] Func5 was called,  res=" + res2);
        
        openHarmonyJSObject.Call("Func6");
        Debug.Log("[test] Func6 was called, test TuanjieSendMessage");
        
        
#endif
    }

    public void OnNativeListener(string msg)
    {
        Debug.Log("[test] received message from ts, msg="+msg);
    }
    
    
    public void OnNativeListener2()
    {
        Debug.Log("[test] received message from ts, no msg");
    }
}
